<template>
  <div class="content">
    <h1 class="title"><i class="fas fa-door-open"></i> 房间管理</h1>
    <table class="data-table">
      <thead>
        <tr>
          <th>房间号</th>
          <th>类型</th>
          <th>图片</th>
          <th>价格</th>
          <th>状态</th>
        </tr>
      </thead>
      <tbody>
        <tr v-for="room in rooms" :key="room.number">
          <td>{{ room.number }}</td>
          <td>{{ room.type }}</td>
          <td>
            <img 
              :src="getRoomImage(room.type)" 
              :alt="room.type" 
              class="room-thumbnail"
              @mouseover="showPreview = room.number"
              @mouseout="showPreview = null"
            >
            <div v-if="showPreview === room.number" class="image-preview">
              <img :src="getRoomImage(room.type)" :alt="room.type">
            </div>
          </td>
          <td>{{ room.price }}</td>
          <td>{{ room.status === 'available' ? '可入住' : '已入住' }}</td>
        </tr>
      </tbody>
    </table>
  </div>
</template>

<script>
// 导入本地图片
import roomType1 from '@/assets/room_type1.jpg';
import roomType2 from '@/assets/room_type2.jpg';
import roomType3 from '@/assets/room_type3.jpg';

export default {
  name: 'RoomManagement',
  data() {
    return {
      showPreview: null,
      roomImages: {
        '标准间': roomType1,  // 使用导入的图片
        '大床房': roomType2,
        '豪华间': roomType3
      }
    }
  },
  computed: {
    rooms() {
      return this.$store.state.rooms
    }
  },
  methods: {
    getRoomImage(type) {
      return this.roomImages[type] || 'https://via.placeholder.com/100'
    }
  }
}
</script>

<style scoped>
/* 之前的样式保持不变 */
.content {
  margin-left: 240px;
  padding: 40px;
  background-color: #f4f6f9;
}

.title {
  font-size: 32px;
  color: #333;
  margin-bottom: 20px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
}

.data-table th,
.data-table td {
  padding: 15px;
  border-bottom: 1px solid #ddd;
  text-align: left;
}

.data-table th {
  background-color: #f2f2f2;
  font-weight: 600;
}

.room-thumbnail {
  width: 80px;
  height: 60px;
  object-fit: cover;
  cursor: pointer;
  transition: transform 0.3s;
}

.room-thumbnail:hover {
  transform: scale(1.05);
}

.image-preview {
  position: absolute;
  z-index: 100;
  padding: 10px;
  background: white;
  border-radius: 4px;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
}

.image-preview img {
  width: 300px;
  height: 200px;
  object-fit: cover;
}
</style>